#pragma once

#include "Callback.h"

using namespace AT;

class CThreadpool
{
public:
	CThreadpool(UINT nMinThread, UINT nMaxThread);
	~CThreadpool();

	bool Init();
	void Exit();
	bool PostTask(ICallbackPtr&& pTask);

	template<typename Fn, typename... Args>
	bool PostTask(Fn&& fn, Args&&... args)
	{
		return PostTask(MakeCallback(std::forward<Fn>(fn), std::forward<Args>(args)...));
	}

private:
	void RunTask();

	const UINT m_nMinThread;
	const UINT m_nMaxThread;
	UINT       m_nThreadNum;
	PTP_WORK   m_pTpWork;
	SRWLOCK    m_SRWLock = SRWLOCK_INIT;
	std::deque<ICallbackPtr> m_deqTasks;
};
